Conditions | 4 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | // jshint esversion: 8 |
||
25 | function fileReadLines(filePath, lines = 2, startLine = 0) { |
||
26 | var lineCounter = startLine, |
||
27 | //endLine = startLine + lines, |
||
28 | linesRead = [], |
||
29 | lineReader = require('readline').createInterface({ |
||
30 | input: require('fs').createReadStream(filePath), |
||
31 | }); |
||
32 | |||
33 | lineReader.on('line', function(line) { |
||
34 | lineCounter++; |
||
35 | linesRead.push(line); |
||
36 | if (lineCounter == lines) lineReader.close(); |
||
37 | }); |
||
38 | |||
39 | lineReader.on('close', function() { |
||
40 | return linesRead; |
||
41 | }); |
||
42 | |||
43 | return 0; |
||
44 | } |
||
45 | |||
50 |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: